package com.ye.zcswzlms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ye.zcswzlms.entity.Lostproperty;
import com.ye.zcswzlms.entity.Users;
import com.ye.zcswzlms.mapper.UsersMapper;
import com.ye.zcswzlms.service.impl.LostpropertyServiceImpl;
import com.ye.zcswzlms.service.impl.UsersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/info")
public class InfoController {
    @Autowired
    LostpropertyServiceImpl lostpropertyService;
    @Autowired
    UsersMapper usersMapper;
    @Autowired
    UsersServiceImpl usersService;

    /**
     * 分页寻物返回物品集合
     * @param currentPage
     * @return
     */
    @GetMapping("/LostInfo")
    List<Lostproperty> lostInfo(int currentPage){
        List<Lostproperty> lostproperties = lostpropertyService
                .queryLostForPage("寻物启事",currentPage);
        return lostproperties;
    }

    /**
     * 分页招领返回物品集合
     * @param currentPage
     * @return
     */
    @GetMapping("/foundInfo")
    List<Lostproperty> foundInfo(int currentPage){
        List<Lostproperty> lostproperties = lostpropertyService
                .queryLostForPage("招领启事",currentPage);
        return lostproperties;
    }
    
    @GetMapping("/userInfo")
    Users userInfo(String userId){
        QueryWrapper qw=new QueryWrapper();
        qw.eq("stuNo",userId);
       return usersMapper.selectOne(qw);
    }
    @GetMapping("/QueryByName")
    List<Lostproperty> querybyname(String sign,String type){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("type",type);
        qw.like("lostPropertyName",sign);
        List list = lostpropertyService.list(qw);
        System.out.println(list);
        return list;
    }

    @GetMapping("/QueryByDivide")
    List<Lostproperty> querybyname1(String divide,String type){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("divid",divide+'类');
        qw.eq("type",type);
        List list = lostpropertyService.list(qw);
        return list;
    }
    @GetMapping("/infoSize")
    int queryZise(String type){
        int i = lostpropertyService.queryNum(type);
        return i;
    }

    @GetMapping("/deletePropertyById")
    void delProperty(int id){
        lostpropertyService.delPropertyById(id);
    }

    /**
     * 获取用户根据页数查询
     * @param page
     * @return
     */
    @GetMapping("/getUser")
    List<Users> getUser(int page){
        List<Users> users = usersService.queryUsers(page);
        return users;
    }


}
